package org.zk.dubbo_consumer.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.zk.entity.Lession;
import org.zk.entity.Teacher;
import org.zk.entity.Tixian;
import org.zk.service.TixianService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 李亚婷
 * @date 2019/12/16 0016 下午 4:30
 */
@Controller
public class TixianController {
    @Resource
    private TixianService tixianService;
@RequestMapping("/toApplyTixian")

    public ModelAndView getApply(){
        return new ModelAndView("/admin/applyTixian");
    }


    /**
     * LYT 2019-12-16 查询平台收到的提现记录（模糊、分页）
     * @param pageSize  每页显示条数
     * @param pageNum 当前页
     * @param teacher 教师
     * @param status 提现状态
     * @param start 提现时间
     * @param end
     * @return map
     */
    @RequestMapping("/getApplyTixian")
    @ResponseBody
    public Map getApplyTixian(int pageSize, int pageNum, Teacher teacher,int status,String start,String end){
        System.out.println("到这了");
        Map map=new HashMap();
        if(!start.equals("")){
            start+= " 00:00:00";
        }
        if(!end.equals("")){
            end+=" 23:59:59";
        }
        map.put("pageSize",pageSize);
        map.put("pageNum",pageNum);
        map.put("seetext",teacher.getTeacherName());
        map.put("status",status);
        map.put("start",start);
        map.put("end",end);
        PageInfo page= tixianService.getApplyTixianPage(map);
        List<Tixian> tx=page.getList();
        for (int i = 0; i < tx.size(); i++) {
            String flag=tx.get(i).getStatus();
            if (flag.equals("0")){
                tx.get(i).setStatus("已处理");
            }
            if (flag.equals("1")){
                tx.get(i).setStatus("未处理");
            }
        }
        map.put("page",page);
        map.put("pages",page.getTotal());//总条数
        map.put("totalPage",page.getPages());//总页数
        return map;
    }

    /**
     * LYT 执行提现操作
     * @param id  提现id
     * @param teacherId 教师id
     * @param model 存放提现详情
     * @return
     */
    @RequestMapping("/tixianDetail/{id}/{teacherId}")
    public String getTeacherZhifubao(@PathVariable("id") int id, @PathVariable("teacherId") int teacherId, Model model){
        Teacher t=tixianService.getTeacherZhifubao(teacherId); /*查询支付宝账号是否存在*/
        if(t.getTeacherZhifubao()!=null){
            model.addAttribute("teacher",t);
            Tixian tixian= tixianService.getTeacherTixian(id);/*查询提现详情*/
            model.addAttribute("tixian",tixian);
        }
         return "admin/tixianDetail";
    }

    /**
     * LYT  更新提现状态
     * @param id
     * @return
     */
    @RequestMapping("/updateStatus")
    @ResponseBody
    public Boolean updateStatus(HttpSession session, int id){
        /*int adminid = (int) session.getAttribute("adminId");*/
        int adminid = 2;
        tixianService.updateTixianStatusTeacher(id,adminid);  /*改变提现状态为已处理*/
        return true;

    }

    /**
     * LYT 删除提现记录
     * @param id
     * @return
     */
    @RequestMapping("/delTixian")
    @ResponseBody()
    public Boolean delTixian(int id){
        tixianService.delTixian(id);/*删除提现记录*/
        return true;
    }








}
